<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" placeholder="请输入locationId" id="">
    <button>点击请求</button>
    <script>
        let inp = document.querySelector("input")
        let btn = document.querySelector("button")
        btn.onclick = function () {
            let xhr = new XMLHttpRequest()
            xhr.open('get', `https://qw6yvxtrrf.re.qweatherapi.com/v7/weather/now?location=${inp.value}&key=d763df9f84c543bd868115c8a02bac8b`)
            xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
            xhr.send()
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    console.log(JSON.parse(xhr.responseText));

                }
            }
        }


    </script>
</body>

</html>